<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>生命周期</title>
  <!-- 开发环境版本，包含了有帮助的命令行警告 -->
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="demo">
  <button @click="desVm">destory vm</button>
  <p v-show="isShow">尚硅谷IT</p>
</div>


<script type="text/javascript">
  const vm = new Vue({
    el: '#demo',
    data:{
     isShow:true
    },
    mounted() {
      this.intId = setInterval(()=> {
        this.isShow = !this.isShow;
      },1000);
    },
    beforeDestroy() {
      //清除定时防止内存泄漏
      clearInterval(this.intId);
    },
    methods:{
      desVm(){
        this.$destroy();
      }
    }
  });

</script>
</body>
</html>